const Base = require("../base.js");
const qr = require("qr-image");
const txyoss = require("./txyoss")
/*生成二维码
https://www.npmjs.com/package/qr-image
https://duxinggj.com/j/?id=10001
*/
module.exports = class extends Base {
  async indexAction() {
    var svg_string = qr.imageSync(this.get("text"), {
      ec_level: this.get("ec_level"),
      type: "svg",
      margin: 0,
      fill: "#f4ea2a",
    });
    this.success(svg_string.replace("d=", `fill="${this.get("color")}" d=`));
  }
  async imgqrAction() {
    var code = qr.image(decodeURIComponent(this.get("text")), {
      type: "png",
      size: 15,
      margin: 1,
    });
    code.pipe(this.ctx.res);
    return this.display();
  }
  async cltAction() {

    var svg_string = qr.imageSync(this.get("text"), {
      ec_level: this.get("ec_level"),
      type: "svg",
      margin: 0,
      fill: "#f4ea2a",
    });
    // this.assign("testsdr",svg_string.replace("d=", `fill="${this.get("color")}" d=`));


    // return this.display()

    const buffer = Buffer.from(svg_string.replace("d=", `fill="${this.get("color")}" d=`));
    const kxcds =  await txyoss.upbuff(buffer,"珠宝检测",".svg")
    return this.success(kxcds)
  }
};
